<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Index_Mobile extends CI_Controller {
	/**
	 /system/core/Common/error
	 $da = error(4001);  返回错误提示  
	 echo _echo($da);   等于 echo json_encode($da, JSON_UNESCAPED_UNICODE);
	 
	 /application/libraries/Mobile_index_service.php  加载 对应 
	 $this->load->library('mobile_index_service');  
	 
	*/

	public function __construct(){
		parent::__construct();
		header('Content-Type: application/json; charset=utf-8');
		$this->load->model('Model_m'); //增删改查 基本类
		$this->load->library('mobile/mobile_index_service');  
	}	

	public function index()
	{	
		
		switch ($_SERVER["REQUEST_METHOD"]) {
			case 'GET':
				$data['act'] = $this->input->get('act');   //首页广告
				$data['pid'] = $this->input->get('pid');  //广告位
				$data['limt'] = $this->input->get('limt'); //数量	
				$ad_index = $this->mobile_index_service->get_index($data);
				
				echo json_encode($ad_index);
				break;
			case 'POST':
				
				break;
			case 'PUT':
				$data['act'] = $this->input->get('act');   //首页广告
				$data['pid'] = $this->input->get('pid');  //广告位
				$data['limt'] = $this->input->get('limt'); //数量	
				$ad_index = $this->mobile_index_service->put_index($data);
				
				echo json_encode($ad_index);
				break;
			case 'DELETE':
				$data['act'] = $this->input->get('act');   //首页广告
				$data['pid'] = $this->input->get('pid');  //广告位
				$data['limt'] = $this->input->get('limt'); //数量	
				$ad_index = $this->mobile_index_service->delete_index($data);
				
				echo json_encode($ad_index);
				break;

			default:
				# code...
				break;
		}
die;
		
	
		if (isset($_REQUEST['act']) == 'article') {
			$act = $this->input->get('article');   //首页文章
			$cat_id = $this->input->get('cat_id');   //文章类型
			$limt = $this->input->get('limt');   //数量	
			
			$article_where = array('is_open'=>1,'cat_id'=>$cat_id); //cat_id=1  文章类别  例：=1新手上路
			$article_index = $this->Model_m->select('article',$article_where,'article_id asc',$limt); //article_index_1  文章_首页_文章类型
			
			echo json_encode($article_index, JSON_UNESCAPED_UNICODE);
		}


		//$this->load->view('mobile/index.html');
	}
}

